<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    年：<input type="text" id="year">
    月：<input type="text" id="month">
    日：<input type="text" id="day">
    <button id="btn">判断</button>
    <input type="text" id="result">
    <script>
    var yearInp = document.getElementById("year");
    var monthInp = document.getElementById("month");
    var dayInp = document.getElementById("day");
    var btn = document.getElementById("btn");
    var resultInp = document.getElementById("result");
    btn.onclick=function(){
        if(yearInp.value!=""){
            // 年份  1000-4000  整数
            if(yearInp.value>1000&&yearInp.value<4000&&yearInp.value%1==0){
                if(monthInp.value!=""){
                    // 月份  1-12  整数
                    if(monthInp.value>=1&&monthInp.value<=12&&monthInp.value%1==0){
                       if(dayInp.value!=""){
                           console.log(monthInp.value*1)
                           var max=0
                           switch(monthInp.value*1){
                              case 1:
                              case 3:
                              case 5:
                              case 7:
                              case 8:
                              case 10:
                              case 12:max=31;
                                     break;
                              case 4:
                              case 6:
                              case 9:
                              case 11:max=30;
                                     break;
                              case 2:if((yearInp.value%4==0&&yearInp.value%100!=0|| year % 400 == 0)){
                                      max=29
                                     }
                                     else{
                                         max=28
                                     }
                            default: resultInp.value=""
                                    break;
                            
                           }
                           console.log(max)
                           if(dayInp.value>=1&&dayInp.value<=max&&dayInp.value%1==0){
                               console.log("日期正确")
                           }else{
                            resultInp.value="日期输入错误"
                           }
                       }
                       else{
                        resultInp.value="日期不能为空"
                       }
                    }
                }
                else{
                    resultInp.value="月份不能为空"
                }
            }
            else{
                resultInp.value="年份输入错误" 
            }
        }
        else{
            resultInp.value="年份不能为空"
        }

    }
    </script>
</body>
</html>